
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <stdint.h>

#if 0
#include "vad.h"

int main(int argc, char *argv[])
{
    FILE *fidr = fopen(argv[1], "rb");
    FILE *fidw = fopen(argv[2], "wb");

    int framelen = 16*20; // 20ms    
    char *inbuf = (char *)malloc(framelen*sizeof(int16_t));

    fseek(fidr, 0, SEEK_END); int T1 = ftell(fidr);
	fseek(fidr, 0, SEEK_SET); int T0 = ftell(fidr);
    int nframes = (T1-T0)/2/framelen;
	printf("total frames = %d \n", nframes);

    wb_vad_enter(300, 500, 320, 800);

    int ret = 0;
    for (int n=0; n<nframes; n++)
    {
        printf("frame = %d\n", n);
        fread(inbuf, sizeof(int16_t), framelen, fidr);
        ret = wb_vad_process(inbuf, framelen*2); // 640 char

        fwrite(&ret, 2, 1, fidw);
    }

    wb_vad_deinit();
    free(inbuf);
    fclose(fidw);
    fclose(fidr);
    printf("vad test..........\n");
    return 0;
}
#endif

#include "vad_api.h"

int main(int argc, char *argv[])
{
    FILE *fidr = fopen(argv[1], "rb");
    FILE *fidw = fopen(argv[2], "wb");

    int framelen = 16*20; // 20ms    
    char *inbuf = (char *)malloc(framelen*sizeof(int16_t));

    fseek(fidr, 0, SEEK_END); int T1 = ftell(fidr);
	fseek(fidr, 0, SEEK_SET); int T0 = ftell(fidr);
    int nframes = (T1-T0)/2/framelen;
	printf("total frames = %d \n", nframes);

    wb_vad_create();

    int ret = 0;
    for (int n=0; n<nframes; n++)
    {
        printf("frame = %d\n", n);
        fread(inbuf, sizeof(int16_t), framelen, fidr);
        ret = wb_vad_run(inbuf, framelen*2); // 640 char

        fwrite(&ret, 2, 1, fidw);
    }

    wb_vad_destroy();

    free(inbuf);
    fclose(fidw);
    fclose(fidr);
    printf("vad test..........\n");
    return 0;
}


